using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NCS.Library.Components.Modules;
using NCS.Library;
using NCS.Library.Utilities;
using NCS.Module.Multimedia.Library.Gallery;

namespace NCS.Module.Multimedia.Library
{
    public class GalleryWebControl : ModuleControlBase
    {
        private int albumTabListId;
        private int alnumPicInAlbumTab;
        private int bonusTabDetailId;
        protected Gallery_AlbumInfo curAlbum;
        protected PictureInfo curPic;
        private int portalid;
        protected int albumid;
        protected int catebonusid;
        protected int picid;
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            portalid = ConvertUtility.ToInt32(AppEnv.PortalId());
            albumTabListId = ConvertUtility.ToInt32(NCS.Library.Components.Portal.PortalSetting.GetSetting()[Definition.Portal_Album_Tab + "_" + AppEnv.PortalId() + "_" + AppEnv.GetLanguage()]);
            alnumPicInAlbumTab = ConvertUtility.ToInt32(NCS.Library.Components.Portal.PortalSetting.GetSetting()[Definition.Portal_AlbumDetail_Tab + "_" + AppEnv.PortalId() + "_" + AppEnv.GetLanguage()]);
            bonusTabDetailId = ConvertUtility.ToInt32(NCS.Library.Components.Portal.PortalSetting.GetSetting()[Definition.Portal_BonusDetail_Tab + "_" + AppEnv.PortalId() + "_" + AppEnv.GetLanguage()]);
             

            albumid = ConvertUtility.ToInt32(Request.QueryString["albumid"]);
            curAlbum = Gallery_AlbumController.GetAlbum(albumid);
            catebonusid = ConvertUtility.ToInt32(Request.QueryString["catebonusid"]);

            picid = ConvertUtility.ToInt32(Request.QueryString["picid"]);
            if (picid != 0)
            {
                curPic = PictureController.GetPicture(picid);
                if (curAlbum == null && curPic != null) curAlbum = Gallery_AlbumController.GetAlbum(curPic.AlbumID);
            }
        }
        protected string BuildUrlByGallery()
        {
            return AppEnv.DEFAULT_PAGE + "?portalid=" + portalid + "&tabid=" + albumTabListId + "&catid=" + Request.QueryString["catid"];
            //return "/portalid/" + portalid + "/tabid/" + albumTabListId + "/catid/" + Request.QueryString["catid"] + AppEnv.DEFAULT_EXTENTSION;
        }
        protected string BuildUrlByAlbum(int _albumid)
        {
            return AppEnv.DEFAULT_PAGE + "?portalid=" + portalid + "&tabid=" + albumTabListId + "&catid=" + Request.QueryString["catid"] + "&albumid=" + _albumid;
            //return "/portalid/" + portalid + "/tabid/" + albumTabListId + "/catid/" + Request.QueryString["catid"] + "/albumid/" + _albumid + AppEnv.DEFAULT_EXTENTSION;
        }
        protected string BuildUrlByAlbum(int _albumid, int catid)
        {
            return AppEnv.DEFAULT_PAGE + "?portalid=" + portalid + "&tabid=" + alnumPicInAlbumTab + "&catid=" + catid + "&albumid=" + _albumid;
            //return "/portalid/" + portalid + "/tabid/" + alnumPicInAlbumTab + "/catid/" + catid + "/albumid/" + _albumid + AppEnv.DEFAULT_EXTENTSION;
        }
        protected string BuildUrlByPicInAlbum(int _albumid)
        {
            return AppEnv.DEFAULT_PAGE + "?portalid=" + portalid + "&tabid=" + alnumPicInAlbumTab + "&catid=0&albumid=" + _albumid;
            //return "/portalid/" + portalid + "/tabid/" + alnumPicInAlbumTab + "/catid/" + Request.QueryString["catid"] + "/albumid/" + _albumid + AppEnv.DEFAULT_EXTENTSION;
            // cho gia tri ve 0
            
            
            //return "/portalid/" + portalid + "/tabid/" + alnumPicInAlbumTab + "/catid/0/albumid/" + _albumid + AppEnv.DEFAULT_EXTENTSION;
        }

        // mr nguyen edit date 12/03/2008  
        //protected string BuildUrlByBonusId(int _bonusid)
        //{
        //    //return AppEnv.DEFAULT_PAGE + "?portalid=" + portalid + "&tabid=" + bonusTabDetailId + "&catid=" + Request.QueryString["catid"]+ "&bonusid=" + _bonusid;
        //    return "/portalid/" + portalid + "/tabid/" + bonusTabDetailId + "/catid/" + Request.QueryString["catid"] + "/bonusid/" + _bonusid + AppEnv.DEFAULT_EXTENTSION;
        //}
        protected string BuildUrlByBonusId(int _bonusid)
        {
            string catid = "";
            try
            {
                catid = Request.QueryString["catid"].ToString();
            }
            catch
            {
                catid = "0";
            }
            return AppEnv.DEFAULT_PAGE + "?portalid=" + portalid + "&tabid=" + bonusTabDetailId + "&catid=" + Request.QueryString["catid"]+ "&bonusid=" + _bonusid;
            //return "/portalid/" + portalid + "/tabid/" + bonusTabDetailId + "/catid/" + catid + "/catebonusid/" + catebonusid + "/bonusid/" + _bonusid + AppEnv.DEFAULT_EXTENTSION;

        }
        protected string BuildUrlByBonusId(int _bonusid, int catid)
        {
            return AppEnv.DEFAULT_PAGE + "?portalid=" + portalid + "&tabid=" + bonusTabDetailId + "&catid=" + catid + "&bonusid=" + _bonusid;
            //return "/portalid/" + portalid + "/tabid/" + bonusTabDetailId + "/catid/" + catid + "/bonusid/" + _bonusid + AppEnv.DEFAULT_EXTENTSION;
        }
        protected string BuildUrlbyPortal(int _portalid)
        {
            return AppEnv.DEFAULT_PAGE + "?portalid=" + _portalid + "&tabid=" + ConvertUtility.ToInt32(Portal[Definition.Portal_Home_Tab + "_" + _portalid + "_" + AppEnv.GetLanguage()]);
            //return "/portalid/" + _portalid + "/tabid/" + ConvertUtility.ToInt32(Portal[Definition.Portal_Home_Tab + "_" + _portalid + "_" + AppEnv.GetLanguage()]) + AppEnv.DEFAULT_EXTENTSION;
        }
        public string BuildUrlImage(int ID, int anbumId)
        {

            return "/portalid/" + portalid + "/tabid/" + Request.QueryString["tabid"].ToString() + "/albumid/" + anbumId + "/picid/" + ID + AppEnv.DEFAULT_EXTENTSION;
            //return AppEnv.DEFAULT_PAGE + "?portalid=" + portalid + "&tabid=" + Request.QueryString["tabid"].ToString() + "&albumid=" + anbumId + "&picid=" + ID;

        }

        protected string BuildUrlByCateBonusInAlbum(int _catebonusid)
        {
            return AppEnv.DEFAULT_PAGE + "?portalid=" + portalid + "&tabid=" + alnumPicInAlbumTab + "&catid=0&catebonusid=" + _catebonusid;
            //return "/portalid/" + portalid + "/tabid/" + alnumPicInAlbumTab + "/catid/" + Request.QueryString["catid"] + "/albumid/" + _albumid + AppEnv.DEFAULT_EXTENTSION;
            // cho gia tri ve 0

            //return "/portalid/" + portalid + "/tabid/" + bonusTabDetailId + "/catid/0/catebonusid/" + _catebonusid + AppEnv.DEFAULT_EXTENTSION;
        }

    }

}
